<?php
namespace app\mini\controller;

use app\index\model\Archive;
use app\index\model\Arctype;

use think\Config;
use think\Request;

class About extends Common
{
    const PERPAGE = 10;
    public function _initialize(){
        parent::_initialize();

    }

    /**
     * 新闻列表
     * @return json $data
     * @author kangyi(997032813@qq.com)
     */
    public function index(Request $request)
    {
        $param = $request->param();
        if (empty($param['curpage'])) {
            $curpage = 1;
        } else {
            $curpage = $param['curpage'];
        }
        $archiveModel = new Archive();
        $typeModel = new Arctype();
        $where['status'] = 1;
        $where['mod'] = 'addonarticle';
        if($param['id']){
            $where['typeid'] = ['eq',$param['id']];
        }
        $order = 'create_time desc,click desc';
        $dataList = $archiveModel->where($where)->order($order)->select()->toArray();
        $total_count = count($dataList);
        $total_page = ceil($total_count/self::PERPAGE);
        $data_list = pageArray($dataList,self::PERPAGE,$curpage);
        $data =array('list'=>$data_list,'total_page'=>$total_page,'total_count'=>$total_count) ;
        outPutData($data);
    }

    /**
     * 新闻详情
     * @author kangyi(997032813@qq.com)
     */

    public function detail()
    {
        $id = input('id');
        if (!$id) {
            outPutData('','缺少关键参数',Config::get('code.mistake'));
        }
        $archiveModel = new Archive();
        $archive = $archiveModel->where(['id'=>$id, 'status'=>1])->find();
        if (empty($archive)) {
            outPutData('','暂无数据',Config::get('code.null'));
        }
        $arctypeModel = new Arctype();
        $arctype = $arctypeModel->where(['id'=>$archive['typeid']])->find();
        $arctype->arctypeMod;
        $archive['addondata'] = $archive->{$arctype->arctypeMod->mod};   //拓展模式表数据
        unset($archive[$arctype->arctypeMod->mod]);
        $data['archive'] = $archive;
        $data['description'] = $archive['description'];
        outPutData($data);
    }



}
